home *** CD-ROM | disk | FTP | other *** search
- /* CLEANUP is a utility program to facilitate the maintanence of the
- USERS file for systems running RBBS-PC CPC12.2 versions B and on.
-
- This program is hereby donated to the public domain as long as these
- comments and source code are not removed or modified in any way.
-
- Donated by: DSOFT
- Author: William K. Davies
- 8990 19th Street #294
- Alta Loma, Ca 91701
- Date: October 2, 1984
- Updated: November 25, 1984 -- Add capability to specify USERS filename.
- Phone: (714)989-6706 <-- Data line running RBBS-PC (300/450/1200)
-
- Although this program is distributed free of charge, a contribution will
- be accepted (suggested $15) for the further development of similar
- software utilities.
-
- */
-
- #include "stdio.h" /* standard I/O routines */
-
- /* define external assembly language routines */
- extern int scr_cls(), scr_clr(), scr_rowcol(), strncmp(), strlen();
- extern int toupper(), gets(), atoi();
-
- /* define data storage */
- FILE *fp;
- char dis_buffer[129], filename[13];
- char name[32], password[16], city_state[25];
- char machine[20], time_date[15], last_dir[4];
- char error;
- int security, op1, op2, op3 ,op4, op5, op6, op7, downloads, uploads, elapsed;
-
- main()
- {
- screen(); /* display title screen */
- scr_clr(); /* clear screen */
-
- crt(20,1,"Enter name of USERS file to cleaned up: ");
- gets(&filename);
- if ((fp = fopen(filename, "r")) == NULL) { /* open users file */
- printf("\n Users file %s not found!\n\n", filename);
- exit(0);
- }
-
- search(); /* call main routine */
- close(fp); /* close users file */
- crt(0, 0, "CLEANUP Done. Have a good day!");
- } /* program ends here */
-
- /* routine to search for a user. (Only characters input are compared) */
-
- search()
- {
- char input[200], again, compare;
- int record;
-
- do {
- crt(20,1,"User Name To Search For: ");
- gets(&input); /* get user name */
- cnvrt_string(input); /* convert to upper case */
- error = rewind(fp); /* reset file pointer */
- record = 0; /* reset record counter */
- do {
- again = 1; /* set repeat flag */
- get_record(); /* read disk record */
- record++; /* increment record counter */
- if (error != 0) { /* error = 0 if no file */
- compare = strncmp(dis_buffer, input, strlen(input));
- if (compare == 0) { /* compare = 0 if match */
- dis_record(record); /* display record */
- crt(20, 1, "Do You Want To Modify This Record (y/n) ");
- again = answer(); /* yes = 1, no = 0 */
- if (again == 1)
- modify(record); /* yes -> modify record */
- again = 0; /* don't continue search */
- }
- } else
- again = 0; /* error -> no repeat */
- } while (again == 1); /* continue search */
- crt(20,1,"Do You Want To Search For Another User (y/n) ");
- again = answer(); /* find another */
- } while (again == 1); /* 1 = again, 0 = end */
- }
-
- /* routine to update the users record with the new information */
-
- modify(record)
- int record;
- {
- char flag, modified, input[200];
-
- do {
- crt(20,1,"Parameter To Modify (0 = End)"); /* get parameter to mod */
- flag = getchar() - '0'; /* read keyboard & convert to decimal */
- switch (flag) {
- case 0: break; /* if zero then we are done! */
- case 1: crt(20,1,"New User Name: ");
- gets(&input);
- update(0, 31, input);
- modified = 1;
- break;
- case 2: crt(20,1,"New User Password: ");
- gets(&input);
- update(31, 15, input);
- modified = 1;
- break;
- case 3: crt(20,1,"New User Security Level: ");
- gets(&input);
- update_word(46, input);
- modified = 1;
- break;
- case 4: crt(20,1,"New User City, State: ");
- gets(&input);
- update(62, 24, input);
- modified = 1;
- break;
- case 5: crt(20, 1, "New User Machine: ");
- gets(&input);
- update(86, 19, input);
- modified = 1;
- break;
- case 6: crt(20, 1, "New User Downloads: ");
- gets(&input);
- update_word(122, input);
- modified = 1;
- break;
- case 7: crt(20, 1, "New User Uploads: ");
- gets(&input);
- update_word(124, input);
- modified = 1;
- break;
- }
- if (flag != 0)
- dis_record(record); /* display modified data */
- } while ( flag != 0);
- crt(20, 1, "OK, To Update USERS file (y/n) ");
- flag = answer();
- if (flag == 1)
- update_users_file(record); /* if not ok, then return nothing changed */
- }
-
- /* routine to write updated users record to the disk */
-
- update_users_file(record)
- int record;
- {
- long file_offset;
-
- rewind(fp);
- file_offset = --record * 128;
- fseek(fp, file_offset, 0);
- write(fp, dis_buffer, 128);
- }
-
- /* routine to update a series of ascii characters in an array */
-
- update(offset, count, string)
- char offset, count, string[];
- {
- char cnt;
- for (cnt = 0; cnt < count; cnt++)
- dis_buffer[offset+cnt] = ' ';
- count = strlen(string);
- cnvrt_string(string);
- for (cnt = 0; cnt < count; cnt++)
- dis_buffer[offset+cnt] = string[cnt];
- }
-
- /* routine to update a integer stored as a two byte ascii string */
-
- update_word(offset, string)
- char offset, string[];
- {
- unsigned number;
- number = atoi(string);
- dis_buffer[offset] = number % 256;
- dis_buffer[offset+1] = number / 256;
- }
-
- /* sets cursor to row, col, and then displays a string */
-
- crt(row, col, s)
- char row, col, s[];
- {
- scr_rowcol(row, col);
- scr_cls();
- printf("%s", s);
- }
-
- /* routine to interagate the keyboard. This routine will wait for a key
- to be depressed. If any key other than a upper or lower case "Y" is
- struck a zero will be returned else a one is returned. */
-
- answer()
- {
- char c;
- c = toupper(getchar());
- if (c == 'Y')
- return(1);
- else
- return(0);
- }
-
- /* routine to convert ascii string to upper case letters */
-
- cnvrt_string(s)
- char *s;
- {
- do {
- *s = toupper(*s);
- } while(*s++);
- }
-
- /* routine to read a users file record from the disk */
-
- get_record()
- {
- char cnt;
- for (cnt = 0; cnt <= 128; cnt++)
- dis_buffer[cnt] = 9;
- error = fread(dis_buffer, 128, 1, fp);
- }
-
- /* this routine takes data read from the users file and converts it to
- variables that are more convenient for display */
-
- convert_data()
- {
- move_data(name, 0, 31);
- move_data(password, 31, 15);
- security = set_word(46);
- op1 = set_word(48);
- op2 = set_word(50);
- op3 = set_word(52);
- op4 = set_word(54);
- op5 = set_word(56);
- op6 = set_word(58);
- op7 = set_word(60);
- move_data(city_state, 62, 24);
- move_data(machine, 86, 19);
- move_data(time_date, 105, 14);
- move_data(last_dir, 119, 3);
- downloads = set_word(122);
- uploads = set_word(124);
- elapsed = set_word(126);
- }
-
- /* moves string array data down (s[]) starting at position start by the
- number passed in count */
-
- move_data(s, start, count)
- char s[], start, count;
- {
- char cnt;
- for (cnt = 0; cnt < count; cnt++)
- s[cnt] = dis_buffer[start+cnt];
- s[++cnt] = '\0';
- }
-
- /* changes to consecutive string bytes into an integer */
-
- set_word(offset)
- char offset;
- {
- char hi, lo;
- hi = dis_buffer[offset+1];
- lo = dis_buffer[offset];
- return(hi * 256 + lo);
- }
-
- /* display data record in the standard format */
-
- dis_record(record)
- int record;
- {
- convert_data(); /* converts data record for display */
- crt(1,3,"Record Number =======> ");
- printf("%d\n", record);
- printf("1. User Name ===========> %s\n", name);
- printf("2. Password ============> %s\n", password);
- printf("3. Security Level ======> %d\n", security);
- printf(" Times On System =====> %d\n", op1);
- printf(" Last Message Read ===> %d\n", op2);
- printf(" Line Feeds ==========> \0");
- print_mode(op3, "ON", "OFF");
- printf(" Right Margin At =====> %d\n", op4);
- printf(" Prompt Bell =========> \0");
- print_mode(op5, "ON", "OFF");
- printf(" Expert/Novice Mode ==> \0");
- print_mode(op6, "NOVICE", "EXPERT");
- printf(" Page Length =========> %d\n", op7);
- printf("4. City, State =========> %s\n", city_state);
- printf("5. Users Machine =======> %s\n", machine);
- printf(" Time/Date Last On ===> %s\n", time_date);
- printf(" Last Directory List => \0");
- printf("%02d/%02d/%02d\n", last_dir[1], last_dir[2], last_dir[0]);
- printf("6. Downloads ===========> %d\n", downloads);
- printf("7. Uploads =============> %d\n", uploads);
- printf(" Elapsed Time (min) ==> %d\n", elapsed);
- }
-
- /* print_mode will print string passed to s1 if flag is zero, else
- the string passed in s2 will be printed */
-
-
- print_mode(flag, s1, s2)
- int flag;
- char s1[], s2[];
- {
- if (flag == 0)
- printf("%s\n", s1);
- else
- printf("%s\n", s2);
- }
-
- /* routine to display opening screen */
-
- screen()
- {
- char c;
-
- scr_clr(); /* clear screen */
- center(7, "CLEANUP -- By William K. Davies");
- center(9, "A USERS file maintenance utility -- DSOFT");
- center(10, "Version 1.1 11/25/1984");
- center(11, "Data (714)989-6706");
- center(24, "Press Enter Key To Continue...");
- do {
- c = getchar(); /* wait for a carriage return */
- } while ( c != 13);
- }
-
- /* routine to display a string centered on the screen at the specified row */
-
- center(row, s)
- char row, s[];
- {
- char l;
-
- l = (80 - strlen(s)) / 2; /* calculate column */
- scr_rowcol(row, l); /* set cursor postion */
- printf("%s\0", s);
- }